package com.zzvcom.util;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
public class FileItem implements java.io.Serializable {
    private static final long serialVersionUID = 1L;
    private String fileId;
    @EqualsAndHashCode.Include
    private String url;
    private String fileName;
    private long size;
    private String officeURL;
    //下载到本地的地址
    private String localPath;
    /**
     * file表
     */
    public static final int DATATYPE_OFFICEFILE = 0;
    /**
     * pdf表的处理
     */
    public static final int DATATYPE_OFFICEPDF= 1;

    private int dataType;

    public FileItem() {
    }

    public FileItem(String fileId, String url, String fileName) {
        this.fileId = fileId;
        this.url = url;
        this.fileName = fileName;
    }

    public String getExt() {
        if (fileName == null) {
            return null;
        }
        if (fileName.lastIndexOf(".") == -1) {
            return null;
        }
        return fileName.substring(fileName.lastIndexOf(".") + 1);
    }

    public String makeCacheName() {
        String ext = getExt();
        if (ext == null) {
            return fileId;
        }
        return fileId + "." + ext;
    }
}
